/**
 * 数据缓存工具类。
 **/
class StorageUtils {
	storage: Storage
	
	constructor(type: StorageType) {
		this.storage =
			(type === StorageType.Local) ? localStorage : sessionStorage
	}
	
	setKey(key: String, value: any) {
		// console.log('setKey ..... key ===>', key)
		// console.log('setKey ..... value ===>', value)
		if (value) {
			this.storage.setItem(key, JSON.stringify(value))
		}
	}
	
	getKey(key: String) {
		// console.log('getKey ..... key ===>', key)
		const value = this.storage.getItem(key)
		// console.log('getKey ..... value ===>', value)
		if (value) {
			return JSON.parse(value)
		}
	}
	
	removeKey(key: String) {
		this.storage.removeItem(key)
	}
	
	clear() {
		this.storage.clear()
	}
}

enum StorageType {
	Local,
	Session
}


const LocalStorageUtils = new StorageUtils(StorageType.Local)
const SessionStorageUtils = new StorageUtils(StorageType.Session)

export { LocalStorageUtils, SessionStorageUtils }